//
//  ZXTabBar.m
//  qianke
//
//  Created by ZX on 2017/6/29.
//  Copyright © 2017年 ZX. All rights reserved.
//

#import "ZXTabBar.h"
#import "AddSaleActivityViewController.h"
@implementation ZXTabBar


- (UIButton *)addButton
{
    if (!_addButton) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame= CGRectMake(0, 0, 90, 120);
        [btn setImage:[UIImage imageNamed:@"add_icon"] forState:UIControlStateNormal];
        [btn setTitle:@"添加意向客户" forState:UIControlStateNormal];
        [btn setTitleColor:baseLittleBlueColor forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:tabbarfontNumber];
        [btn addTarget:self action:@selector(addClick) forControlEvents:UIControlEventTouchUpInside];
        btn.imageEdgeInsets = UIEdgeInsetsMake(- (btn.frame.size.height - btn.titleLabel.frame.size.height- btn.titleLabel.frame.origin.y),(btn.frame.size.width -btn.titleLabel.frame.size.width)/1.0f -btn.imageView.frame.size.width, -5, 0);
        btn.titleEdgeInsets = UIEdgeInsetsMake(btn.frame.size.height-btn.imageView.frame.size.height-btn.imageView.frame.origin.y, -btn.imageView.frame.size.width, 0, 0);
        [self addSubview:btn];
        _addButton = btn;
    }
    return _addButton;
}

- (void)addClick
{
    if (_str.intValue == 0) {
        [[NSNotificationCenter defaultCenter]postNotificationName:addcustomer object:nil];
    }else{
        [[NSNotificationCenter defaultCenter]postNotificationName:addcustomer2 object:nil];
    }
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundImage = [UIImage imageNamed:@"tabbar-light"];
    }
    _str = @"0";
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getIndexes:) name:selectedIndexStr object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(addClick) name:@"wodeaddsaleactivity" object:nil];
    return self;
}
-(void)getIndexes:(NSNotification *)notification{
    NSString * str =  [notification.userInfo objectForKey:selectedIndexStr];
    _str = str;
    NSLog(@"%@",str);
    
}

/**
 *  布局子控件
 */
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 发布按钮
    self.addButton.centerX = self.width * 0.5;
    self.addButton.centerY = self.height * 0.33;
   
    // 处理其他按钮
    CGFloat buttonW = self.width / 3;
    CGFloat i = 0;
    for (UIView *tabBarButton in self.subviews) {
        if (![NSStringFromClass(tabBarButton.class) isEqualToString:@"UITabBarButton"]) continue;
        
        tabBarButton.width = buttonW;
        tabBarButton.x = i * buttonW;
        if (i > 0) tabBarButton.x += buttonW;
        
        i++;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
